package com.metadata_system.api_server.auth_server;

import org.springframework.web.bind.annotation.*;
import com.metadata_system.api.annotations.ApiCheckSign;
import com.metadata_system.api.annotations.ImageVerifiyCode;
import com.metadata_system.common.dto.ApiResult;
import com.metadata_system.common.enums.EmailVerifyEventType;
import com.metadata_system.common.enums.ImageVerifyEventType;
import com.metadata_system.common.enums.MobileVerifyEventType;
import com.metadata_system.common.http.request_dto.EmailVerifyRequest;
import com.metadata_system.common.http.request_dto.MobileVerifyRequest;
import com.metadata_system.common.service.ImageVerifyCodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import com.metadata_system.common.service.SliderCaptchaService;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;

@RestController("authVerifyController")
@Slf4j
@RequestMapping(value = "/api/auth-server/v001/Verify/")
public class VerifyController {

    @Autowired
    ImageVerifyCodeService imageVerifyCodeService;
    @Autowired
    SliderCaptchaService sliderCaptchaService;


    // 创建图片验证码
    @RequestMapping(value = "createImage", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiCheckSign
    public void createImage(
            @RequestParam String eventType,
            @RequestParam String deviceId,
            HttpServletResponse response) throws IOException {
        // 创建验证码
        BufferedImage verifyImage = imageVerifyCodeService.generate(deviceId, ImageVerifyEventType.fromString(eventType));
        // 响应返回图片
        response.setHeader("Content-Type", "image/jpeg");
        ImageIO.write(verifyImage, "JPEG", response.getOutputStream());
    }



}
